package org.cc.cloud;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;

public class MyInterceptor  implements ClientHttpRequestInterceptor{

	public ClientHttpResponse intercept(final HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
			throws IOException {
//		System.out.println("================这是自定义拦截器           "+request.getURI());
		HttpRequest newRequest=new HttpRequest(){

	
			public HttpHeaders getHeaders() {
				// TODO Auto-generated method stub
				return request.getHeaders();
			}

			public HttpMethod getMethod() {
				// TODO Auto-generated method stub
				return request.getMethod();
			}

			public URI getURI() {
				// TODO Auto-generated method stub
//				try {
//					URI url=new URI("http://www.baidu.com");
//					return url;
//				} catch (URISyntaxException e) {
//					// TODO Auto-generated catch block
//					
//				}
				return request.getURI();
			}
			
		};
		// TODO Auto-generated method stub
		return execution.execute(newRequest, body);
	}

}
